package com.ty.day6.home;

import java.io.*;
import java.util.Scanner;

/**
 * Created by IntelliJ IDEA.
 *
 * @author : txy
 * @create : 2023/11/29 17:25
 */
public class Task1 {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        //字节流
        FileOutputStream fos = new FileOutputStream("D:\\test.txt");
        FileInputStream fis = new FileInputStream("D:\\test.txt");
        //字节流到字符流桥接器
        OutputStreamWriter osw = new OutputStreamWriter(fos);
        InputStreamReader isr = new InputStreamReader(fis);
        //字符流
        BufferedWriter bw = new BufferedWriter(osw);
        BufferedReader br = new BufferedReader(isr);

        System.out.println("请输入字符(两次回车结束):");
        String in;
        //输入的不是空就继续执行循环
        while (!(in = sc.nextLine()).isEmpty()){
            //写入输入的内容
            bw.write(in);
            //写一个换行符
            bw.newLine();
        }
        System.out.println("写入完成\n");
        //将缓存文字写入文件
        bw.flush();
        //读取文件
        System.out.println("开始读取...\n");
        String out;
        while((out=br.readLine())!=null){
            System.out.println(out);
        }
        System.out.println("\n读取完毕");
        //关闭流
        bw.close();
        br.close();
        osw.close();
        isr.close();
        fis.close();
        fos.close();
    }
}
